package haw.pr2.A3.implementations;

import haw.pr2.A3.interfaces.BoundingBox;
import haw.pr2.A3.interfaces.Length;
import java.util.Collection;
import java.util.Iterator;
import static haw.pr2.A3.implementations.UtilityclassValues.*;

/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class BoundingBoxImpl implements BoundingBox {
    
    private final Length length,width,height;
    
    public BoundingBoxImpl(Length length, Length width, Length height) {
        this.length=length;
        this.width=width;
        this.height=height;
    }

    @Override
    public Length length() {
        return this.length;
    }

    @Override
    public Length width() {
        return this.width;
    }

    @Override
    public Length height() {
        return this.height;
    }

    @Override
    public boolean fitsInto(BoundingBox boundingBox) {
        return ((this.length().m() < boundingBox.length().m()) 
                && (this.width().m() < boundingBox.width().m())
                && (this.height().m() < boundingBox.height().m()));
    }


    @Override
    public BoundingBox addAll(Collection boxes) {
        BoundingBox res = UtilityclassValues.boundingBox(ZERO_LENGTH, ZERO_LENGTH, ZERO_LENGTH);
        for (Iterator<BoundingBox> it = boxes.iterator(); it.hasNext();) {
            BoundingBox boundingBox = it.next();
            res.add(boundingBox);
        }
        return res;
    }

    @Override
    public BoundingBox add(BoundingBox bBox) {
        return new BoundingBoxImpl(this.length.add(bBox.length()), this.width.add(bBox.width()), this.height.add(bBox.height()));
    }

   
}